home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / emac16as.arc / TI.ASM < prev    next >
Assembly Source File  |  1990-04-01  |  21KB  |  978 lines

  1.     page    ,132
  2.  
  3. comment /
  4.  
  5.     Porting EMACS and Percival to MS-DOS computers other than the Z-100:
  6.  
  7. This entire file (Z-100.ASM) needs to be re-written, since it contains
  8. all the Z-100 dependencies.  The following conventions must be maintained:
  9.   1) Never leave this module with DF=1.
  10.   2) Never destroy ES.
  11.   3) Never MOV AX,DATA, always use the copy in the appropriate segment register.
  12.   4) Return NC if a routine succeeds, or fulfills its goals.
  13.  
  14. /
  15. ;    .xlist
  16.     include    memory.def
  17.  
  18.  
  19. data    segment    byte public
  20.  
  21.     public    max_screen_line
  22. max_screen_line    db    22    ;number of last text row on screen.
  23.  
  24.     public    num_screen_cols
  25. num_screen_cols    db    80
  26.     db    0            ;in case they access it as a word.
  27.  
  28.     public    fore_original, back_original
  29. fore_original    db    ?
  30. back_original    db    ?
  31.  
  32.  
  33.     public    scan_lines_per_char
  34. scan_lines_per_char    db    8
  35.  
  36. mouse_flag    db    ?
  37. mouse_buttons    db    ?
  38.  
  39.  
  40.     public    computer_name, computer_name_len
  41. computer_name    db    'TI-PC'
  42. computer_name_len    equ    $-computer_name
  43.  
  44.     public    swap_screen_flag
  45. swap_screen_flag    dw    1    ;=1 if we should swap screens.
  46.  
  47. old_cursor    dw    ?        ;old cursor position from the swapped
  48.                     ;  screen.
  49.  
  50. key_names    label    byte
  51.     db    ',','Comma',0
  52.     db    '(','LPar',0
  53.     db    ')','RPar',0
  54.     db    7fh,'Delete',0
  55.  
  56.     db    -1,'Timeout',0
  57.   if 0
  58.     db    -2,'Left Down',0        ;mouse button key names.
  59.     db    -3,'Right Down',0
  60.     db    -4,'Left Up',0
  61.     db    -5,'Right Up',0
  62.     db    -6,'Middle Down',0
  63.     db    -7,'Middle Up',0
  64.   endif
  65.     db    0
  66.  
  67.  
  68.   if 0
  69. ; This table contains the scan codes of ASCII control characters that
  70. ; have dedicated keys.  (This table is not used on the TI PC since
  71. ; the scan code is not returned for ASCII characters.)
  72. key_others    label    byte
  73.     db    21,'Back Space',0
  74.     db    26,'Tab',0
  75.     db    77,'Return',0
  76.     db    65,'Escape',0
  77.     db    62,'Line Feed',0
  78.     db    0
  79.  
  80. ; This table contains the control states of keys from the "others" table.
  81. ; Since the search in the "others" table never succeeds on the TI PC,
  82. ; this table table is not used on the TI PC.
  83.  
  84. key_special    label    byte
  85.     db    7Fh,'C-Back Space',0
  86.     db    0Ah,'C-Return',0
  87.     db    0
  88.   endif
  89.  
  90. ; The following table maps extended functions codes returned by the TI
  91. ; PC BIOS to associate key names.
  92. key_table    label    byte
  93.     db      01h,'Pause',0
  94.  
  95.     db    03h,'C-@',0
  96.  
  97.         db    08h,'S-F11',0
  98.         db    09h,'S-F12',0
  99.         db    0Ah,'C-F11',0
  100.         db    0Bh,'C-F12',0
  101.         db    0Ch,'M-F11',0
  102.         db    0Dh,'M-F12',0
  103.  
  104.     db    0Fh,'S-Tab',0
  105.     db    10h,'M-q',0
  106.     db    11h,'M-w',0
  107.     db    12h,'M-e',0
  108.     db    13h,'M-r',0
  109.     db    14h,'M-t',0
  110.     db    15h,'M-y',0
  111.     db    16h,'M-u',0
  112.     db    17h,'M-i',0
  113.     db    18h,'M-o',0
  114.     db    19h,'M-p',0
  115.  
  116.     db    1Eh,'M-a',0
  117.     db    1Fh,'M-s',0
  118.     db    20h,'M-d',0
  119.     db    21h,'M-f',0
  120.     db    22h,'M-g',0
  121.     db    23h,'M-h',0
  122.     db    24h,'M-j',0
  123.     db    25h,'M-k',0
  124.     db    26h,'M-l',0
  125.  
  126.     db    28h,'S-Ins',0
  127.     db    29h,'C-Ins',0
  128.     db    2Ah,'M-Ins',0
  129.  
  130.     db    2Ch,'M-z',0
  131.     db    2Dh,'M-x',0
  132.     db    2Eh,'M-c',0
  133.     db    2Fh,'M-v',0
  134.     db    30h,'M-b',0
  135.     db    31h,'M-n',0
  136.     db    32h,'M-m',0
  137.  
  138.     db    38h,'S-Del',0
  139.     db    39h,'C-Del',0
  140.     db    3Ah,'M-Del',0
  141.     db    3Bh,'F1',0
  142.     db    3Ch,'F2',0
  143.     db    3Dh,'F3',0
  144.     db    3Eh,'F4',0
  145.     db    3fH,'F5',0
  146.     db    40h,'F6',0
  147.     db    41h,'F7',0
  148.     db    42h,'F8',0
  149.     db    43h,'F9',0
  150.     db    44h,'F10',0
  151.     db    45h,'F11',0
  152.     db    46h,'F12',0
  153.     db    47h,'Home',0
  154.     db    48h,'Up Arrow',0
  155.     db    49h,'M-Up Arrow',0
  156.  
  157.     db    4Bh,'Left Arrow',0
  158.     db    4Ch,'M-Left Arrow',0
  159.     db    4Dh,'Right Arrow',0
  160.     db    4Eh,'M-Right Arrow',0
  161.     db    4Fh,'M-Line Feed',0
  162.     db    50h,'Down Arrow',0
  163.     db    51h,'M-Down Arrow',0
  164.     db    52h,'Ins',0
  165.     db    53h,'Del',0
  166.     db    54h,'S-F1',0
  167.     db    55h,'S-F2',0
  168.     db    56h,'S-F3',0
  169.     db    57h,'S-F4',0
  170.     db    58h,'S-F5',0
  171.     db    59h,'S-F6',0
  172.     db    5Ah,'S-F7',0
  173.     db    5Bh,'S-F8',0
  174.     db    5Ch,'S-F9',0
  175.     db    5Dh,'S-F10',0
  176.     db    5Eh,'C-F1',0
  177.     db    5Fh,'C-F2',0
  178.     db    60h,'C-F3',0
  179.     db    61h,'C-F4',0
  180.     db    62h,'C-F5',0
  181.     db    63h,'C-F6',0
  182.     db    64h,'C-F7',0
  183.     db    65h,'C-F8',0
  184.     db    66h,'C-F9',0
  185.     db    67h,'C-F10',0
  186.     db    68h,'M-F1',0
  187.     db    69h,'M-F2',0
  188.     db    6Ah,'M-F3',0
  189.     db    6Bh,'M-F4',0
  190.     db    6Ch,'M-F5',0
  191.     db    6Dh,'M-F6',0
  192.     db    6Eh,'M-F7',0
  193.     db    6Fh,'M-F8',0
  194.     db    70h,'M-F9',0
  195.     db    71h,'M-F10',0
  196.     db    72h,'Print',0
  197.     db    73h,'C-Left Arrow',0
  198.     db    74h,'C-Right Arrow',0
  199.     db    75h,'C-Line Feed',0
  200.     db    76h,'C-Down Arrow',0
  201.     db    77h,'C-Home',0
  202.     db    78h,'M-1',0
  203.     db    79h,'M-2',0
  204.     db    7Ah,'M-3',0
  205.     db    7Bh,'M-4',0
  206.     db    7Ch,'M-5',0
  207.     db    7Dh,'M-6',0
  208.     db    7Eh,'M-7',0
  209.     db    7Fh,'M-8',0
  210.     db    80h,'M-9',0
  211.     db    81h,'M-0',0
  212.     db    82h,'M--',0
  213.     db    83h,'M-=',0
  214.     db    84h,'C-Up Arrow',0
  215.     db    85h,'M-Home',0
  216.     db    86h,'S-Home',0
  217.  
  218.     db    88h,'S-Up Arrow',0
  219.     db    89h,'S-Down Arrow',0
  220.     db    8Ah,'S-Right Arrow',0
  221.     db    8Bh,'S-Left Arrow',0
  222.     db    8Ch,'PF1',0
  223.     db    8Dh,'PF2',0
  224.     db    8Eh,'PF3',0
  225.     db    8Fh,'PF4',0
  226.  
  227.     db    0,'Unknown',0
  228.  
  229. break_key:
  230.     db    'Break',0
  231.  
  232.  
  233. one_key_string    db    ?,0
  234. ctrl_key_string    db    'C-'
  235. ctrl_key_char    db    ?,0
  236.  
  237. shift_flag    equ    4
  238. ctrl_flag    equ    1
  239. alt_flag    equ    2
  240. all_flags    equ    shift_flag + ctrl_flag + alt_flag
  241. shift_flags    db    ?
  242.  
  243. key_buffer    label    byte        ;this is where we put the ASCII
  244.     db    26 dup(?)        ;  representation of the key.
  245.  
  246.  
  247.     extrn    inversing: word        ;if we're inverse videoing.
  248.  
  249. ; The following are initialized since screen writes occur before  
  250. ; init_entry is called.
  251.  
  252. fore_color db    ?            ; 000reccc r: reverse; e: enable;
  253. back_color db    ?            ;          c: color
  254.  
  255. font_8_table    label    byte
  256.     db    007h            ;visi space
  257.     db    004h            ;visi tab
  258.     db    ?            ;del
  259.     db    ?            ;eof
  260.     db    ?            ;visi newline
  261.     db    01ah            ;right arrow
  262.     db    ?            ;random char.
  263.     db    01fh            ;visible newline.
  264.  
  265. data    ends
  266.  
  267.  
  268. code    segment    byte public
  269.     assume    cs:code, ds:data, es:nothing
  270. ;all of the code in this segment is called with the above assumes.
  271.  
  272. break_flag    db    ?
  273.  
  274. their_break    dd    ?
  275. our_break proc    far
  276.     mov    cs:break_flag,1
  277.     stc
  278.     ret    2
  279. our_break endp
  280.  
  281. their_map    dd    ?
  282. our_map    proc    far
  283.  
  284. ; This temporary keyboard mapping routine replaces C-space,
  285. ; M-space, and M-C-space by C-@, M-@, and M-C-@, respectively,
  286. ; provided Shift is not depressed.
  287.  
  288. ; A more complex mapping routine could be used to permit combinations
  289. ; such as M-C-x and to disambiguate the special ASCII keys such as Tab
  290. ; and Line Feed from their control equivalents; they cannot be
  291. ; distnguished on the TI PC since the BIOS does not return the scan
  292. ; code for a normal ASCII character.  (Note that disambiguating the
  293. ; special ASCII keys would force usage of  a nonstandard character
  294. ; representation  such as an addition to the extended function codes;
  295. ; however this might introduce problems with chained keyboard mapping
  296. ; routines or characters that are left in the keyboard buffer when
  297. ; subtasks are invoked.)
  298.  
  299. ; AH contains the mode bits and AL the scan code.
  300.     test    ah,alt_flag+ctrl_flag
  301.     je    our_map_exit        ; jump if neither alt or ctrl
  302.     test    ah,shift_flag
  303.     jne    our_map_exit        ; jump if shift
  304.     cmp    al,81            ; space
  305.     jne    our_map_exit        ; jump if not space
  306.     or    ah,shift_flag        ; replace space with @
  307.     mov    al,10
  308. our_map_exit:
  309.     jmp    their_map        ; give others a chance
  310.  
  311. our_map    endp
  312.  
  313.  
  314.     public    init_entry
  315. init_entry:
  316.     push    es            ; get their C-break.
  317.     mov     al,5Dh            ; keyboard break interrupt
  318.     mov    ah,35h
  319.     int    21h
  320.     mov    word ptr their_break+0,bx
  321.     mov    word ptr their_break+2,es
  322.     pop    es
  323.  
  324.     push    ds            ;set our C-break.
  325.     mov    ax,cs
  326.     mov    ds,ax
  327.     mov    dx,offset our_break
  328.     mov    al,5Dh            ; keyboard break interrupt
  329.     mov    ah,25h
  330.     int    21h
  331.     pop    ds
  332.  
  333.     push    es            ; get their keyboard mapping vector
  334.     mov     al,5Bh
  335.     mov    ah,35h
  336.     int    21h
  337.     mov    word ptr their_map+0,bx
  338.     mov    word ptr their_map+2,es
  339.     pop    es
  340.  
  341.     push    ds            ; set our keyboard mapping interrupt
  342.     mov    ax,cs
  343.     mov    ds,ax
  344.     mov    dx,offset our_map
  345.     mov    al,5Bh            ; keyboard mapping interrupt
  346.     mov    ah,25h
  347.     int    21h
  348.     pop    ds
  349.  
  350.     push    ax
  351.     push    dx
  352.     push    di
  353.     push    es
  354.  
  355. ; Use the attributes of the character at the approximate middle of the
  356. ; screen to set the original foreground and background colors.  This is
  357. ; not completely satisfactory since the screen IO used by COMMAND.COM
  358. ; apparently sets the attributes of trailing blanks on output lines to
  359. ; the color white.  The best approach is to select colors using
  360. ; EDIT-OPTIONS.
  361.     mov    dh,num_screen_cols    ; last column
  362.     dec    dh
  363.     mov    dl,max_screen_line    ; last line
  364.     add    dl,2
  365.     shr    dh,1            ; approximate mid points
  366.     shr     dl,1
  367.     call    get_video_ptr
  368.     mov    al,es:[di]        ; read a character to get its attributes
  369.     mov    ax,0DF80h        ; read the attribute latch
  370.     mov    es,ax
  371.     mov    al,es:[0]
  372.     and    al,07h            ; isolate the color
  373.     mov    fore_original,al
  374.     or    al,08h            ; The TI PC does not have a background
  375.     mov    back_original,al    ; color; use reverse video.
  376.  
  377. ; Set the current colors since the copyright notice is written before
  378. ; the screen colors are set.
  379.     push    ds
  380.     pop    es
  381.     mov    ah,back_original
  382.     mov    al,fore_original
  383.     call    set_screen_color
  384.  
  385.     pop    es
  386.     pop    di
  387.     pop    dx
  388.     pop    ax
  389.  
  390.     ret
  391.  
  392.  
  393.     public    uninit_exit
  394. uninit_exit:
  395. ; called when exiting (including suspending to invoke another program).
  396. ; May destroy any but seg-regs.
  397.     push    ds            ; restore C-break.
  398.     mov     al,5Dh            ; keyboard break interrupt
  399.     lds    dx,their_break
  400.     mov    ah,25h
  401.     int    21h
  402.     pop    ds
  403.  
  404.     push    ds            ; restore keyboard mapping
  405.     mov     al,5Bh
  406.     lds    dx,their_map
  407.     mov    ah,25h
  408.     int    21h
  409.     pop    ds
  410.  
  411. ; set the attribute latch to the default foreground color and position
  412. ; the cursor on the last line.
  413.  
  414.     mov    dl,max_screen_line    ; last line
  415.     add    dl,2
  416.     mov    dh,0            ; column 0
  417.     call    clear_to_eol
  418.     call    position_cursor
  419.  
  420.     ret
  421.  
  422.  
  423.     public    store_ibm_cga
  424. store_ibm_cga:
  425.     ret
  426.  
  427.  
  428.     public    store_debug
  429. store_debug:
  430.   if 0
  431.     push    ds
  432.     push    es
  433.     push    ax
  434.     mov    ax,data
  435.     mov    ds,ax
  436.     mov    es,ax
  437.     mov    dh,num_screen_cols
  438.     sub    dh,2
  439.     mov    dl,max_screen_line
  440.     inc    dl
  441.     call    get_video_ptr    ;enter with dl=current row, dh=current column.
  442.                 ;return with es:di->character position.
  443.     pop    ax
  444.     mov    es:[di],al
  445.     mov    es:[di+2],ah
  446.     pop    es
  447.     pop    ds
  448. store_debug_1:
  449.   endif
  450.     ret
  451.  
  452.  
  453. ;this routine should check for a break character.  Return cy if none,
  454. ;  nc if we should break.
  455.     public    check_breakchar
  456. check_breakchar:
  457.     cmp    cs:break_flag,0        ;test the break flag.
  458.     mov    cs:break_flag,0        ;clear the break flag.
  459.     stc
  460.     je    check_breakchar_1
  461.     clc
  462. check_breakchar_1:
  463.     ret
  464.  
  465.  
  466.     public    give_up_slice
  467. give_up_slice:
  468.     ret
  469.  
  470.  
  471.     public    check_for_key
  472. check_for_key:
  473. ;return zr,ax=0 if no key is waiting.
  474. ;return nz,ax=key if a key is waiting, but don't input the key yet.
  475.     mov    ah,01h            ; check keyboard status
  476.     int    4Ah
  477.     jne    check_for_key_1        ;go if we got a key.
  478.     mov    ax,0            ;return ax=0 if we didn't.
  479. check_for_key_1:
  480.     ret
  481.  
  482.  
  483.     public    get_key_value
  484. get_key_value:
  485. ;exit with ax=keycode.
  486.     mov    ah,00h            ; keyboard input
  487.     int    4Ah
  488.     ret
  489.  
  490.  
  491.     public    decode_key
  492. decode_key:
  493. ;enter with ax=key value.
  494. ;exit with si,cx -> the key's name in ASCII.
  495.     mov    di,offset key_buffer
  496.  
  497.   if 0
  498.     cmp    ax,0f9h            ;one of the mouse buttons?
  499.     jb    decode_key_7
  500.     cmp    ax,0feh
  501.     ja    decode_key_7
  502.  
  503. ; mouse buttons:
  504.     push    ax
  505.     mov     ah,02h            ; keyboard mode
  506.     int    4Ah
  507.     and    al,all_flags        ;isolate the flags we're interested in.
  508.     mov    shift_flags,al
  509.     call    decode_meta
  510.     call    decode_ctrl
  511.     call    decode_shift
  512.     pop    ax
  513.  
  514. decode_key_7:
  515.   endif
  516.  
  517.     or    al,al            ;extended function key?
  518.     je    decode_key_5
  519.     cmp    al,0e0h
  520.     je    decode_key_5
  521.  
  522.   if 0
  523. ; The following code searches for ASCII control characters that have
  524. ; dedicated keys so those keys can be distinguished from their C-
  525. ; counterparts; for example, Return and C-m return different strings.
  526. ; (Since the TI PC BIOS always returns 0 in AH if the value in AL is not
  527. ; 0, this technique does not work on the TI PC.)
  528.     push    ax            ;now we look for ASCII keys that
  529.     mov    si,offset key_others    ;  have dedicated keys.
  530.     call    decode_search        ;search for the scan code names.
  531.     pop    ax
  532.     jne    decode_key_2        ;go if we found it.
  533.   endif
  534.  
  535.     mov    ah,al
  536.     mov    si,offset key_names    ;now search for the ASCII keys that
  537.                     ;  we don't (or can't) represent.
  538.     call    decode_search        ;search for the literal names.
  539.     jne    decode_key_1        ;copy it in.
  540.     mov    al,ah
  541.     cmp    al,' '            ;control char?
  542.     jae    decode_key_6        ;no
  543.     add    al,'`'            ;yes - convert into letter.
  544.     mov    ctrl_key_char,al
  545.     mov    si,offset ctrl_key_string
  546.     cmp    al,'z'            ;control character > 'C-z'?
  547.     jbe    decode_key_1        ;no.
  548.     sub    ctrl_key_char,'`'-'@'    ;yes - make it C-[, not C-{
  549.     jmp    short decode_key_1
  550.  
  551.   if 0
  552. ; This code decodes dedicated keys found in the "others" table whose
  553. ; C- version is special; e.g., the C- form of Back Space is 7Fh, which
  554. ; is Delete or C-Back Space.  Since the search in the "others" table
  555. ; never succeeds on the TI PC, this code cannot be reached.
  556. decode_key_2:
  557.     push    si
  558.     mov    si,offset key_special
  559.     mov    ah,al            ;now see if it's one of the ones we
  560.     call    decode_search        ;  know are special.
  561.     pop    ax
  562.     jne    decode_key_1        ;yes - it is.
  563.     mov    si,ax
  564.     jmp    short decode_key_1
  565.   endif
  566.  
  567. ; Process a non-control ASCII character.
  568. decode_key_6:
  569.     mov    one_key_string,al
  570.     mov    si,offset one_key_string
  571.     jmp    short decode_key_1
  572.  
  573. ; Process an extended function key.  On the TI PC, 00h is the
  574. ; representation of the Break key, which requires special processing due
  575. ; 00h being used to indicate the end of a table.  (Since the break is
  576. ; detected via an interrupt, this special handling for Break not needed.)
  577. decode_key_5:
  578.     mov    si,offset break_key
  579.     cmp    ah,0
  580.     je    decode_key_1
  581.     mov    si,offset key_table    ;search for the extended functions.
  582.     call    decode_search
  583. decode_key_1:
  584.     lodsb                ;copy to the next null.
  585.     stosb
  586.     or    al,al
  587.     jne    decode_key_1
  588.     dec    di            ;don't include the null.
  589.     mov    si,offset key_buffer
  590.     mov    cx,di
  591.     sub    cx,si
  592.     ret
  593.  
  594.  
  595.   if 0
  596. ; The following decode pseudo keys entered via the mouse, so are not
  597. ; needed on the TI PC.
  598. decode_ctrl:
  599.     test    shift_flags,ctrl_flag
  600.     je    decode_ctrl_1
  601.     mov    ax,'C' + '-'*256
  602.     stosw
  603. decode_ctrl_1:
  604.     ret
  605.  
  606.  
  607. decode_shift:
  608.     test    shift_flags,left_flag + right_flag
  609.     je    decode_shift_1
  610.     mov    ax,'S' + '-'*256
  611.     stosw
  612. decode_shift_1:
  613.     ret
  614.  
  615. decode_meta:
  616.     test    shift_flags,alt_flag
  617.     je    decode_meta_1
  618.     mov    ax,'M' + '-'*256
  619.     stosw
  620. decode_meta_1:
  621.     ret
  622.   endif
  623.  
  624.  
  625. decode_search:
  626. ;enter with ah=key to search for, si->table.
  627. ;exit with al=key, nz if found, al=0, zr if not found.
  628.     lodsb
  629.     or    al,al            ;end of table?
  630.     je    decode_search_2        ;yes - try shifted values.
  631.     cmp    al,ah            ;is this the key?
  632.     je    decode_search_2        ;yes.
  633. decode_search_1:
  634.     lodsb                ;skip to the next null.
  635.     or    al,al
  636.     jne    decode_search_1
  637.     jmp    decode_search
  638. decode_search_2:
  639.     or    al,al
  640.     ret
  641.  
  642.  
  643.     public    ring_the_bell
  644. ring_the_bell:
  645.     mov    cx,1563        ; 1250000 Hz / 800 Hz
  646.     mov    ah,02h        ; set frequency
  647.     int    48h        ; speaker DSR
  648.     mov     al,20        ; 0.5 sec = 20 * 25 msec
  649.     mov    ah,0        ; sound speaker
  650.     int    48h        ; speaker DSR
  651.     ret
  652.  
  653. code    ends
  654.  
  655. code    segment    byte public
  656.     assume    cs:code, ds:nothing, es:data, ss:data
  657. ;all of the code in this segment is called with the above assumes.
  658.  
  659.  
  660.     public    read_ibm_cga
  661. read_ibm_cga:
  662.     mov    al,0
  663.     ret
  664.  
  665.  
  666.     public    position_cursor
  667. position_cursor:
  668. ;enter with dh=col (0...80), dl=row (0..max_screen_line)
  669. ;exit with cursor set to that position.
  670.     push    ax
  671.     push    cx
  672.     push    dx
  673.     mov    ah,02h
  674.     int    49h
  675.     pop    dx
  676.     pop    cx
  677.     pop    ax
  678.     ret
  679.  
  680.  
  681.     public    move_line
  682. move_line:
  683. ;enter with dl=source row, al=destination row.
  684.     push    ax
  685.     push    bx
  686.     push    cx
  687.     push    dx
  688.     push    si
  689.     push    di
  690.     push    bp
  691.     push    ds
  692.     push    es
  693.  
  694.     push    ax
  695.     xor    dh,dh            ; compute source address
  696.     call    get_video_ptr
  697.     mov    si,di
  698.     assume    es:nothing
  699.     mov    ax,es
  700.     mov    ds,ax
  701.  
  702.     pop    dx            ; compute destination address
  703.     xor    dh,dh
  704.     call    get_video_ptr
  705.  
  706.     mov    cx,word ptr num_screen_cols    ; move the line.
  707.     rep    movsb
  708.  
  709. move_line_3:
  710.     pop    es
  711.     assume  es:data
  712.     pop    ds
  713.     pop    bp
  714.     pop    di
  715.     pop    si
  716.     pop    dx
  717.     pop    cx
  718.     pop    bx
  719.     pop    ax
  720.     ret
  721.  
  722.  
  723.     public    clear_to_eol
  724. clear_to_eol:
  725. ;enter with dl=current row, dh=current column.
  726.     push    bx
  727.     mov    bl,num_screen_cols
  728.     call    clear_count
  729.     pop    bx
  730.     ret
  731.  
  732.  
  733.     public    clear_count
  734. clear_count:
  735. ;enter with dl=current row, dh=current column, bl=column to clear to.
  736.     cmp    dh,bl        ;already past it?
  737.     jae    clear_count_0    ;yes.
  738.  
  739.     push    ax
  740.     push    bx
  741.     push    cx
  742.     push    dx
  743.     push    di
  744.     push    es
  745.  
  746.     mov    ah,fore_color
  747. ;    mov    cx,inversing        ; inverse video flag - 0000 or FFFFh
  748. ;    and    cl,10h            ; inverse bit only
  749. ;    xor    ah,cl            ; flip inverse bit in attribute byte
  750.     mov    cx,0DF80h        ; attribute latch at DF80:0000
  751.     mov    es,cx
  752.     assume    es:nothing
  753.     mov    es:[0],ah
  754.     xor    cx,cx
  755.     mov    cl,bl
  756.     sub    cl,dh
  757.     call    get_video_ptr
  758.     mov    al,' '
  759.     rep    stosb
  760.  
  761.     pop    es
  762.     assume    es:data
  763.     pop     di
  764.     pop    dx
  765.     pop    cx
  766.     pop    bx
  767.     pop    ax
  768.  
  769. clear_count_0:
  770.     ret
  771.  
  772. get_video_ptr:
  773. ;enter with dl=current row, dh=current column.
  774. ;return with es:di->character position.
  775.     push    ax
  776.     push    cx
  777.     push    dx
  778.     mov    al,num_screen_cols    ;compute the offset of the char.
  779.     mul    dl
  780.     add    al,dh
  781.     adc    ah,0
  782.     mov    di,ax
  783.     mov    ah,17h        ; get physical display address
  784.     int    49h
  785.     add    di,dx
  786.     mov    ax,0DE00h
  787.     mov    es,ax
  788.     pop    dx
  789.     pop    cx
  790.     pop    ax
  791.     ret
  792.  
  793.     public    xychrout
  794. xychrout:
  795. ;enter with dh=col, dl=row, al=character to print, ah=font to print it in.
  796.     push    ax
  797.     push    bx
  798.     push    cx
  799.     push    dx
  800.     push    di
  801.     push    ds
  802.     push    es
  803.  
  804.     cmp    dh,num_screen_cols    ; past the right margin?
  805.     jae    xychrout_1        ; yes - do not print
  806.     cmp    ah,0            ; font zero?
  807.     jne    xychrout_not_font_0    ; no
  808.     mov    ah,fore_color
  809.  
  810. ; The following will display characters in the range 80h to FFh using
  811. ; inverse video of the corresponding character in the range 00h to 7Fh.
  812. ; Otherwise, the characters will be displayed using whatever the PC
  813. ; has in its font.
  814.   if 0
  815.     cmp    al,80h            ; meta character?
  816.     jb    xychrout_not_meta    ; no
  817.     xor    ah,10h            ; yes - inverse video
  818.     and    al,7Fh            ; mask meta bit
  819. xychrout_not_meta:
  820.   endif
  821.  
  822.     cmp    al,20h            ; control character?
  823.     jae    xychrout_not_control    ; no
  824.     or    ah,20h            ; yes - underline
  825.     add    al,'@'            ; convert to printable
  826. xychrout_not_control:
  827.     jmp    short xychrout_2
  828. xychrout_not_font_0:
  829.     mov    ah,fore_color
  830.     mov    bx,offset font_8_table
  831.     sub    al,4Dh            ; first character in font 8
  832.     mov    cx,es
  833.     mov    ds,cx
  834.     xlat
  835. xychrout_2:
  836.     mov    bx,inversing        ; inverse video flag - 0000 or FFFFh
  837.     and    bl,10h            ; inverse bit only
  838.     xor    ah,bl            ; flip inverse bit in attribute byte
  839.     mov    bx,0DF80h        ; attribute latch at DF80:0000
  840.     mov    es,bx
  841.     assume    es:nothing
  842.     mov    es:[0],ah
  843.     call    get_video_ptr
  844.     stosb
  845. xychrout_1:
  846.     pop    es
  847.     assume  es:data
  848.     pop    ds
  849.     pop    di
  850.     pop    dx
  851.     pop    cx
  852.     pop    bx
  853.     pop    ax
  854.     ret
  855.  
  856.  
  857.     public    hardware_roll_down
  858. hardware_roll_down:
  859. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  860. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  861. ;  on the screen as the last line.
  862. ;preserve bx.
  863.  
  864.   if 0
  865. ; The following BIOS call is too slow since the screen is repainted
  866. ; after each line.
  867.     push    bx
  868.     push    cx
  869.     push    dx
  870.     mov    dh,0            ; source column
  871.     mov    dl,ah            ; source row
  872.     mov    bh,0            ; destination column
  873.     mov    bl,dl            ; destination row
  874.     inc    bl
  875.     mov    ch,num_screen_cols    ; column length
  876.     mov    cl,al            ; lines to scroll
  877.     sub    cl,ah
  878.     mov    al,0            ; blank exposed lines
  879.     mov    ah,07h
  880.     int    49h
  881.     pop    dx
  882.     pop    cx
  883.     pop    bx
  884.     clc
  885.     ret
  886.   endif
  887. no_roll_down:
  888.     stc
  889.     ret
  890.  
  891.  
  892.     public    hardware_roll_up
  893. hardware_roll_up:
  894. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  895. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  896. ;  on the screen as the last line.
  897. ;preserve bx.
  898.  
  899.   if 0
  900. ; The following BIOS call is too slow since the screen is repainted
  901. ; after each line.
  902.     push    bx
  903.     push    cx
  904.     push    dx
  905.     mov    bh,0            ; destination column
  906.     mov    bl,ah            ; destination row
  907.     mov    dh,0            ; source column
  908.     mov    dl,bl            ; source row
  909.     inc    dl
  910.     mov    ch,num_screen_cols    ; column length
  911.     mov    cl,al            ; lines to scroll
  912.     sub    cl,ah
  913.     mov    al,0            ; blank exposed lines
  914.     mov    ah,06h
  915.     int    49h
  916.     pop    dx
  917.     pop    cx
  918.     pop    bx
  919.     clc
  920.     ret
  921.   endif
  922. no_roll_up:
  923.     stc
  924.     ret
  925.  
  926.  
  927.     public    set_screen_color
  928. set_screen_color:
  929. ;enter with al=fore color, ah=back color
  930.  
  931. ; Process the foreground color.
  932.     push    ax
  933.     mov    ah,al
  934.     and    al,07h        ; isolate the color bits
  935.     and    ah,08h        ; isolate bit 3
  936.      shl     ah,1        ; shift into position for reverse video
  937.     or    ah,08h        ; add the character enable bit
  938.     or    al,ah        ; combine with the color bits
  939.     mov    fore_color,al
  940.     pop    ax
  941.  
  942. ; Process the background color.
  943.     mov    al,ah
  944.     and    al,07h        ; isolate the color bits
  945.     and    ah,08h        ; isolate bit 3
  946.      shl     ah,1        ; shift into position for reverse video
  947.     or    ah,08h        ; add the character enable bit
  948.     or    al,ah        ; combine with the color bits
  949.     mov    back_color,al
  950.     ret
  951.  
  952.  
  953.     public    pick_init, pick_on, pick_off, check_pick, get_pick_values
  954. pick_init:
  955.     mov    mouse_flag,0
  956.     ret
  957.  
  958.  
  959. pick_on:
  960. pick_off:
  961.     ret
  962.  
  963.  
  964. check_pick:
  965. ;return nz and al=pick character.  return zr if no pick.
  966.     xor    al,al
  967.     ret
  968.  
  969.  
  970. get_pick_values:
  971.     mov    cx,0
  972.     mov    dx,0
  973.     ret
  974.  
  975. code    ends
  976.  
  977.     end
  978.